var fs = require('fs');
var data = [{
	"count": 1595,
	"id": -100,
	"ids": [-100, 7, 8, 1, 4, 3],
	"level": 1,
	"image_url": "8644e1323e3a11137d7478d2c83095d4png",
	"name": "美食",
	"sub_categories": [{
		"count": 565,
		"id": 7,
		"image_url": "18eedac58bbcfd59e4a2805abfe11ff2jpeg",
		"level": 1,
		"name": "小吃炸串"
	}, {
		"count": 439,
		"id": 8,
		"image_url": "6f8c0289b217b04fffd70c5f1f397103png",
		"level": 1,
		"name": "地方菜系"
	}, {
		"count": 428,
		"id": 1,
		"image_url": "d8515995a32586701f3c184f422cf66apng",
		"level": 1,
		"name": "简餐便当"
	}, {
		"count": 86,
		"id": 4,
		"image_url": "f36695c9aab9774acbf5ba7e553b8a99jpeg",
		"level": 1,
		"name": "香锅冒菜"
	}, {
		"count": 77,
		"id": 3,
		"image_url": "808fc83b1b9fe47e04219466b269c3bapng",
		"level": 1,
		"name": "汉堡披萨"
	}]
}, {
	"count": 1451,
	"id": 207,
	"ids": [207],
	"level": 1,
	"image_url": "44545a0518aab93817cfe611e88bb702png",
	"name": "快餐便当",
	"sub_categories": [{
		"count": 550,
		"id": 882,
		"image_url": "44545a0518aab93817cfe611e88bb702png",
		"level": 2,
		"name": "其他快餐"
	}, {
		"count": 262,
		"id": 209,
		"image_url": "66b78c0e7099c278977298d7c6042c80png",
		"level": 2,
		"name": "盖浇饭"
	}, {
		"count": 133,
		"id": 754,
		"image_url": "",
		"level": 2,
		"name": "米粉米线"
	}, {
		"count": 86,
		"id": 214,
		"image_url": "4d347d0dc65dd75fb2911256aabf2327png",
		"level": 2,
		"name": "麻辣烫"
	}, {
		"count": 83,
		"id": 266,
		"image_url": "c09d1ff71384e2e1664f72e0a928810dpng",
		"level": 2,
		"name": "烧腊饭"
	}, {
		"count": 80,
		"id": 778,
		"image_url": "",
		"level": 2,
		"name": "粥店"
	}, {
		"count": 77,
		"id": 212,
		"image_url": "7d47af01fccc46fc3621865a9cc07c93png",
		"level": 2,
		"name": "汉堡薯条"
	}, {
		"count": 51,
		"id": 362,
		"image_url": "2c2b370dbd2ef58da58b57944bf971a8png",
		"level": 2,
		"name": "肠粉"
	}, {
		"count": 48,
		"id": 269,
		"image_url": "180cb951c2d4eb2e220debf4571bf83apng",
		"level": 2,
		"name": "煲仔饭"
	}, {
		"count": 47,
		"id": 762,
		"image_url": "",
		"level": 2,
		"name": "面馆"
	}, {
		"count": 43,
		"id": 442,
		"image_url": "4ce1650964d0f2393383ca558449a6e2png",
		"level": 2,
		"name": "木桶饭"
	}, {
		"count": 41,
		"id": 450,
		"image_url": "db5110761ce2d86822f83254acb47391png",
		"level": 2,
		"name": "炒饭"
	}, {
		"count": 39,
		"id": 794,
		"image_url": "",
		"level": 2,
		"name": "饺子"
	}, {
		"count": 35,
		"id": 842,
		"image_url": "",
		"level": 2,
		"name": "滋补炖汤"
	}, {
		"count": 27,
		"id": 746,
		"image_url": "",
		"level": 2,
		"name": "螺蛳粉"
	}, {
		"count": 26,
		"id": 267,
		"image_url": "79637dc36d67de4fe48d121ea77b3eddpng",
		"level": 2,
		"name": "黄焖鸡米饭"
	}, {
		"count": 26,
		"id": 802,
		"image_url": "",
		"level": 2,
		"name": "馄饨抄手"
	}, {
		"count": 23,
		"id": 370,
		"image_url": "20718bc2e86dd26bc88b9bc5b2721acfpng",
		"level": 2,
		"name": "沙县小吃"
	}, {
		"count": 23,
		"id": 770,
		"image_url": "",
		"level": 2,
		"name": "包子汤包"
	}, {
		"count": 23,
		"id": 786,
		"image_url": "",
		"level": 2,
		"name": "豆浆油条"
	}, {
		"count": 20,
		"id": 474,
		"image_url": "972c05a7db9b9b9503868468a909a555png",
		"level": 2,
		"name": "粉丝汤"
	}, {
		"count": 15,
		"id": 394,
		"image_url": "bc74aa2b0fbbcbe659fd5fa6b61571f7png",
		"level": 2,
		"name": "兰州拉面"
	}, {
		"count": 15,
		"id": 434,
		"image_url": "d020995ad0194aaf7b1683bd314d26ccpng",
		"level": 2,
		"name": "烤肉拌饭"
	}, {
		"count": 14,
		"id": 466,
		"image_url": "9de7137c1a09c76184d2c0cd9061b3d5png",
		"level": 2,
		"name": "烤鸭熟食"
	}, {
		"count": 14,
		"id": 826,
		"image_url": "",
		"level": 2,
		"name": "牛肉汤"
	}, {
		"count": 13,
		"id": 850,
		"image_url": "",
		"level": 2,
		"name": "蒸鸡滋补鸡"
	}, {
		"count": 11,
		"id": 386,
		"image_url": "e7c6ac0d26994ecef0655002fb5b26f5png",
		"level": 2,
		"name": "重庆小面"
	}, {
		"count": 11,
		"id": 426,
		"image_url": "4668d6a11c7beb972690f2f31f1d5c9epng",
		"level": 2,
		"name": "脆皮鸡饭"
	}, {
		"count": 11,
		"id": 818,
		"image_url": "",
		"level": 2,
		"name": "排骨饭"
	}, {
		"count": 10,
		"id": 402,
		"image_url": "49bab8f8ccfd09d1e7e8bce770056700png",
		"level": 2,
		"name": "凉皮"
	}, {
		"count": 10,
		"id": 858,
		"image_url": "",
		"level": 2,
		"name": "肉夹馍"
	}, {
		"count": 9,
		"id": 268,
		"image_url": "cdf208b399b854e456f23d28b1972e97png",
		"level": 2,
		"name": "咖喱饭"
	}, {
		"count": 9,
		"id": 490,
		"image_url": "f7cad3d30a88d24367afce8fa370892fpng",
		"level": 2,
		"name": "煎饼"
	}, {
		"count": 7,
		"id": 354,
		"image_url": "9db3d8914794f9211381d1458f4bd8c4png",
		"level": 2,
		"name": "酸辣粉"
	}, {
		"count": 5,
		"id": 378,
		"image_url": "aa4d566bcd87da22baa318bb367726d3png",
		"level": 2,
		"name": "热干面"
	}, {
		"count": 5,
		"id": 458,
		"image_url": "1c724f24062cc94fbf0397a45134f82apng",
		"level": 2,
		"name": "冒菜"
	}, {
		"count": 3,
		"id": 810,
		"image_url": "",
		"level": 2,
		"name": "牛肉饭"
	}, {
		"count": 2,
		"id": 418,
		"image_url": "ca9190cbfb2edc51d102940e258321ddpng",
		"level": 2,
		"name": "锅贴"
	}, {
		"count": 2,
		"id": 890,
		"image_url": "",
		"level": 2,
		"name": "瓦罐汤"
	}, {
		"count": 1,
		"id": 498,
		"image_url": "01401316d62208f5ad289d972cfb8ca3png",
		"level": 2,
		"name": "驴肉火烧"
	}, {
		"count": 1,
		"id": 874,
		"image_url": "",
		"level": 2,
		"name": "烧饼"
	}, {
		"count": 1,
		"id": 906,
		"image_url": "",
		"level": 2,
		"name": "沙茶面"
	}, {
		"count": 1,
		"id": 914,
		"image_url": "",
		"level": 2,
		"name": "北京炸酱面"
	}]
}, {
	"count": 436,
	"id": 220,
	"ids": [220],
	"level": 1,
	"image_url": "6f8c0289b217b04fffd70c5f1f397103png",
	"name": "特色菜系",
	"sub_categories": [{
		"count": 221,
		"id": 221,
		"image_url": "43b0e4694f8ebc393cce6723d5df5222png",
		"level": 2,
		"name": "川湘菜"
	}, {
		"count": 150,
		"id": 222,
		"image_url": "e320bf1ab9762cb1faad27d79f51219cpng",
		"level": 2,
		"name": "粤菜"
	}, {
		"count": 34,
		"id": 232,
		"image_url": "a33f1ec0044ddd4d282fbc8b1f0a946fpng",
		"level": 2,
		"name": "海鲜"
	}, {
		"count": 18,
		"id": 263,
		"image_url": "94ac841e2c3e27f8eeeaa917574ed574png",
		"level": 2,
		"name": "其他菜系"
	}, {
		"count": 15,
		"id": 562,
		"image_url": "",
		"level": 2,
		"name": "茶餐厅"
	}, {
		"count": 7,
		"id": 570,
		"image_url": "",
		"level": 2,
		"name": "私房菜"
	}, {
		"count": 6,
		"id": 223,
		"image_url": "aa4de1e9b54170cf495d8052407658c5png",
		"level": 2,
		"name": "东北菜"
	}, {
		"count": 4,
		"id": 226,
		"image_url": "741d15270496d7699dd2e7804fccc7a1png",
		"level": 2,
		"name": "西北菜"
	}, {
		"count": 2,
		"id": 224,
		"image_url": "54dabf93116f4a336fcc91431be43828png",
		"level": 2,
		"name": "云南菜"
	}, {
		"count": 2,
		"id": 225,
		"image_url": "2d098842683548f9626cf0a8c879257dpng",
		"level": 2,
		"name": "江浙菜"
	}, {
		"count": 2,
		"id": 228,
		"image_url": "a7e6d9cf1993fa4fe0bd02d74d40c9c2png",
		"level": 2,
		"name": "新疆菜"
	}, {
		"count": 2,
		"id": 554,
		"image_url": "",
		"level": 2,
		"name": "闽菜"
	}, {
		"count": 2,
		"id": 698,
		"image_url": "",
		"level": 2,
		"name": "陕西菜"
	}, {
		"count": 1,
		"id": 546,
		"image_url": "",
		"level": 2,
		"name": "江西菜"
	}, {
		"count": 1,
		"id": 594,
		"image_url": "",
		"level": 2,
		"name": "清真菜"
	}, {
		"count": 1,
		"id": 634,
		"image_url": "",
		"level": 2,
		"name": "海南菜"
	}, {
		"count": 1,
		"id": 690,
		"image_url": "",
		"level": 2,
		"name": "甘肃菜"
	}]
}, {
	"count": 165,
	"id": 260,
	"ids": [260],
	"level": 1,
	"image_url": "754c5c2ad1b01668a7186ec5f0fb0e59png",
	"name": "全球美食",
	"sub_categories": [{
		"count": 36,
		"id": 1234,
		"image_url": "78c45200d58e5c02cb70fb8287df732dpng",
		"level": 2,
		"name": "其他西餐"
	}, {
		"count": 29,
		"id": 1058,
		"image_url": "78c45200d58e5c02cb70fb8287df732dpng",
		"level": 2,
		"name": "沙拉"
	}, {
		"count": 24,
		"id": 1138,
		"image_url": "cf8c84a2fe5ecf27b21bcbddc1724d36png",
		"level": 2,
		"name": "刺身寿司"
	}, {
		"count": 23,
		"id": 1162,
		"image_url": "cf8c84a2fe5ecf27b21bcbddc1724d36png",
		"level": 2,
		"name": "韩国炸鸡"
	}, {
		"count": 20,
		"id": 1114,
		"image_url": "cf8c84a2fe5ecf27b21bcbddc1724d36png",
		"level": 2,
		"name": "日本料理"
	}, {
		"count": 19,
		"id": 1042,
		"image_url": "bb7eb2afe778ba9afbe54f9d282818d1png",
		"level": 2,
		"name": "披萨"
	}, {
		"count": 17,
		"id": 1122,
		"image_url": "cf8c84a2fe5ecf27b21bcbddc1724d36png",
		"level": 2,
		"name": "日式简餐"
	}, {
		"count": 9,
		"id": 1154,
		"image_url": "cf8c84a2fe5ecf27b21bcbddc1724d36png",
		"level": 2,
		"name": "韩国料理"
	}, {
		"count": 9,
		"id": 1178,
		"image_url": "78c45200d58e5c02cb70fb8287df732dpng",
		"level": 2,
		"name": "焗饭"
	}, {
		"count": 8,
		"id": 1050,
		"image_url": "bb7eb2afe778ba9afbe54f9d282818d1png",
		"level": 2,
		"name": "意面"
	}, {
		"count": 7,
		"id": 1066,
		"image_url": "78c45200d58e5c02cb70fb8287df732dpng",
		"level": 2,
		"name": "三明治"
	}, {
		"count": 5,
		"id": 1146,
		"image_url": "cf8c84a2fe5ecf27b21bcbddc1724d36png",
		"level": 2,
		"name": "韩式简餐"
	}, {
		"count": 5,
		"id": 1186,
		"image_url": "78c45200d58e5c02cb70fb8287df732dpng",
		"level": 2,
		"name": "牛排"
	}, {
		"count": 1,
		"id": 1074,
		"image_url": "614053401fddc171eed0436f3cd1f7dcpng",
		"level": 2,
		"name": "泰国菜"
	}, {
		"count": 1,
		"id": 1170,
		"image_url": "cf8c84a2fe5ecf27b21bcbddc1724d36png",
		"level": 2,
		"name": "韩式烤肉"
	}, {
		"count": 1,
		"id": 1202,
		"image_url": "78c45200d58e5c02cb70fb8287df732dpng",
		"level": 2,
		"name": "意大利菜"
	}, {
		"count": 1,
		"id": 1226,
		"image_url": "78c45200d58e5c02cb70fb8287df732dpng",
		"level": 2,
		"name": "中亚/中东菜"
	}]
}, {
	"count": 565,
	"id": 233,
	"ids": [233],
	"level": 1,
	"image_url": "7d714540b1590552d991fd731e8772a3png",
	"name": "小吃夜宵",
	"sub_categories": [{
		"count": 189,
		"id": 978,
		"image_url": "90483b16d9598aec798263220eb3a821png",
		"level": 2,
		"name": "其他小吃"
	}, {
		"count": 177,
		"id": 218,
		"image_url": "3c6e2763cf4ee56f18fd1b7360585fb3png",
		"level": 2,
		"name": "烧烤"
	}, {
		"count": 119,
		"id": 234,
		"image_url": "71164ef684e8a13b5e66a20a1c55671cpng",
		"level": 2,
		"name": "炸鸡炸串"
	}, {
		"count": 111,
		"id": 236,
		"image_url": "d049fb617edcea921185258d1675db83png",
		"level": 2,
		"name": "小龙虾"
	}, {
		"count": 40,
		"id": 1474,
		"image_url": "efdba78945f83ed1e8e6e838718b4c65png",
		"level": 2,
		"name": "卤味鸭脖"
	}, {
		"count": 18,
		"id": 962,
		"image_url": "90483b16d9598aec798263220eb3a821png",
		"level": 2,
		"name": "花甲"
	}, {
		"count": 6,
		"id": 1018,
		"image_url": "90483b16d9598aec798263220eb3a821png",
		"level": 2,
		"name": "卤煮火烧"
	}, {
		"count": 4,
		"id": 970,
		"image_url": "90483b16d9598aec798263220eb3a821png",
		"level": 2,
		"name": "章鱼小丸子"
	}, {
		"count": 1,
		"id": 1034,
		"image_url": "90483b16d9598aec798263220eb3a821png",
		"level": 2,
		"name": "烤冷面"
	}]
}, {
	"count": 857,
	"id": -102,
	"ids": [-102, 12, 11, 9, 10],
	"level": 1,
	"image_url": "cac2f06034f8e73eb7793b08c1987049png",
	"name": "甜品饮品",
	"sub_categories": [{
		"count": 298,
		"id": 12,
		"image_url": "ac94b005c97ef158282326cb49389893png",
		"level": 1,
		"name": "面包蛋糕"
	}, {
		"count": 270,
		"id": 11,
		"image_url": "62c31de0a7f41231e4c6934dea621a33png",
		"level": 1,
		"name": "奶茶果汁"
	}, {
		"count": 263,
		"id": 9,
		"image_url": "213cbac0242d4845d1d28af0fa5fe35epng",
		"level": 1,
		"name": "甜品"
	}, {
		"count": 26,
		"id": 10,
		"image_url": "c2f05ef82a7ee44b7848b7fb598d42e3png",
		"level": 1,
		"name": "咖啡"
	}]
}, {
	"count": 148,
	"id": 252,
	"ids": [252],
	"level": 1,
	"image_url": "df21b511f287ccb402e68285d2653caepng",
	"name": "商店超市",
	"sub_categories": [{
		"count": 82,
		"id": 271,
		"image_url": "841d136b17fa4cb871a296c9e4997cfapng",
		"level": 2,
		"name": "便利店"
	}, {
		"count": 29,
		"id": 254,
		"image_url": "92ae70438be9a3adfc5a560c1e6ae818png",
		"level": 2,
		"name": "大型超市"
	}, {
		"count": 13,
		"id": 274,
		"image_url": "7df84232aebbb5ffb53e564c9e328d31png",
		"level": 2,
		"name": "名酒坊"
	}, {
		"count": 7,
		"id": 273,
		"image_url": "c2b0e2b27ea55a9a7211f14ad95dcd0apng",
		"level": 2,
		"name": "休闲零食"
	}, {
		"count": 5,
		"id": 1394,
		"image_url": "",
		"level": 2,
		"name": "美妆个护"
	}, {
		"count": 3,
		"id": 258,
		"image_url": "54b7ce87994d6770f1ead57b0038c569png",
		"level": 2,
		"name": "茶行"
	}, {
		"count": 3,
		"id": 282,
		"image_url": "c28c16653a037261f47eec43f5a7adc6png",
		"level": 2,
		"name": "饮料冰品"
	}, {
		"count": 2,
		"id": 1386,
		"image_url": "",
		"level": 2,
		"name": "日用百货"
	}, {
		"count": 1,
		"id": 255,
		"image_url": "825031dc99e1f99c26feb7186b6cf3a6png",
		"level": 2,
		"name": "水站"
	}, {
		"count": 1,
		"id": 256,
		"image_url": "f6460e330d25dabd4fd8db07cf53f039png",
		"level": 2,
		"name": "奶站"
	}, {
		"count": 1,
		"id": 257,
		"image_url": "b435af6662fd0b3e9fb6537474753f72png",
		"level": 2,
		"name": "粮油副食"
	}, {
		"count": 1,
		"id": 298,
		"image_url": "e2b9d3e00a2cc80c95389206b681558bpng",
		"level": 2,
		"name": "宠物超市"
	}, {
		"count": 1,
		"id": 1410,
		"image_url": "",
		"level": 2,
		"name": "服装鞋包"
	}]
}, {
	"count": 300,
	"id": 275,
	"ids": [275],
	"level": 1,
	"image_url": "49e9cad976ae50274ec36fcf911505e2png",
	"name": "鲜花绿植",
	"sub_categories": [{
		"count": 287,
		"id": 330,
		"image_url": "4080dde0a257591ecb6294d31f938b48png",
		"level": 2,
		"name": "鲜花"
	}, {
		"count": 14,
		"id": 338,
		"image_url": "c5ec07778f90bae26b042d3cec2106e2png",
		"level": 2,
		"name": "绿植"
	}]
}, {
	"count": 40,
	"id": 276,
	"ids": [276],
	"level": 1,
	"image_url": "e72b62bec62175b8a57cbdc4a95c5f2bpng",
	"name": "医药健康",
	"sub_categories": [{
		"count": 28,
		"id": 306,
		"image_url": "cece178a0e243f6b95847c8875ff612cpng",
		"level": 2,
		"name": "药店"
	}, {
		"count": 12,
		"id": 314,
		"image_url": "a09977cd2fe2355b4dd078fb4218d5depng",
		"level": 2,
		"name": "成人用品"
	}]
}]

var index = 1;
let json = ''
var data2 = []
// for (let i = 0; i < data.length;i++) {
//   console.log(data)
// }
for (let i = 0; i < data.length;i++) {
  json += `{"parent_id": 0, "count": 0, "id": ${index}, "image_url": "${data[i].image_url}","name": "${data[i].name}","level":${data[i].level}}\n`
  data2.push({ "parent_id": index, sub: data[i].sub_categories})
  index++
} 
for (let i = 0; i < data2.length; i++) {
  for (let j = 0 ; j < data2[i].sub.length; j++) {
    json += `{"parent_id": ${data2[i].parent_id}, "count": 0, "id": ${index}, "image_url": "${data2[i].sub[j].image_url}","name": "${data2[i].sub[j].name}","level":${data2[i].sub[j].level}}\n`
    index++
  }
}

fs.writeFileSync('./categories.json', json);